<?php
session_start(); 
include('system/connect.php');
 $sql = "SELECT
        chat2_chanels.id,
        chat2_chanels.girl_src,
        chat2_chanels.user_src,
        chat2_chanels.user_id,  
        chat2_chanels.last_active
        FROM
        chat2_chanels                                                                 
        WHERE
        chat2_chanels.user_id <> '0'";
$t = mysql_query($sql);
$result = array();
while ($row = mysql_fetch_assoc($t)) {
    $result[] = $row;
}  
foreach($result as $item) {
    if ((time() - $item['last_active']) > 360) {      
        $id = $item['id'];
        echo("[CLEAR] Chanel: ".$item['girl_src']."($id) - User timeout\n");
        $sql = "update chat2_chanels set user_id = 0 where id = $id";
        mysql_query($sql);                                         
        $sql = "update sf_guard_user set have_chanel=0 where id = '".$item['user_id']."'";
        mysql_query($sql);                
    }
}                                     
?>